package com.ruoyi.match.service.impl;

import java.util.List;

import com.ruoyi.match.domain.MemberTeam;
import com.ruoyi.match.domain.vo.InviteVo;
import com.ruoyi.match.mapper.MemberTeamMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.match.mapper.InviteMapper;
import com.ruoyi.match.domain.Invite;
import com.ruoyi.match.service.IInviteService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 邀请Service业务层处理
 * 
 * @author zhangrui
 * @date 2025-04-08
 */
@Service
public class InviteServiceImpl implements IInviteService 
{
    @Autowired
    private InviteMapper inviteMapper;

    @Autowired
    private MemberTeamMapper memberTeamMapper;

    /**
     * 查询邀请
     * 
     * @param fromId 邀请主键
     * @return 邀请
     */
    @Override
    public Invite selectInviteByFromId(Long fromId)
    {
        return inviteMapper.selectInviteByFromId(fromId);
    }

    /**
     * 查询邀请列表
     * 
     * @param invite 邀请
     * @return 邀请
     */
    @Override
    public List<Invite> selectInviteList(Invite invite)
    {
        return inviteMapper.selectInviteList(invite);
    }

    /**
     * 新增邀请
     * 
     * @param invite 邀请
     * @return 结果
     */
    @Override
    public int insertInvite(Invite invite)
    {
        return inviteMapper.insertInvite(invite);
    }

    /**
     * 修改邀请
     * 
     * @param invite 邀请
     * @return 结果
     */
    @Override
    public int updateInvite(Invite invite)
    {
        return inviteMapper.updateInvite(invite);
    }

    /**
     * 批量删除邀请
     * 
     * @param fromIds 需要删除的邀请主键
     * @return 结果
     */
    @Override
    public int deleteInviteByFromIds(Long[] fromIds)
    {
        return inviteMapper.deleteInviteByFromIds(fromIds);
    }

    /**
     * 删除邀请信息
     * 
     * @param fromId 邀请主键
     * @return 结果
     */
    @Override
    public int deleteInviteByFromId(Long fromId)
    {
        return inviteMapper.deleteInviteByFromId(fromId);
    }

    /**
     * 查询我发出的邀请列表
     */
    @Override
    public List<InviteVo> showMyInviteList(Long userId) {


        return inviteMapper.showMyInviteList(userId);
    }
    /**
     * 查询我收到的邀请列表
     */
    @Override
    public List<InviteVo> showInviteMeList(Long userId) {
        return inviteMapper.showInviteMeList(userId);
    }

    @Override
    @Transactional
    public int acceptInviting(Invite invite) {
        //更新邀请状态
        inviteMapper.updateInvitingStatus(invite);
        MemberTeam memberTeam = new MemberTeam();
        memberTeam.setUserId(invite.getToId());
        memberTeam.setTeamId(invite.getTeamId());

        //插入成员-队伍表
        return memberTeamMapper.insertMemberTeam(memberTeam);
    }


    @Override
    public int rejectInviting(Invite invite) {
        return inviteMapper.updateInvitingStatus(invite);
    }
}
